package com.keruyun.portal.whitelist.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.gateway.config.GatewayLoadBalancerClientAutoConfiguration;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;
import java.util.function.Predicate;

/**
 * <p>
 * Description: com.keruyun.portal.whitelist.gateway
 * </p>
 * date：2018/6/29
 * email:crowhyc@163.com
 *
 * @author Dean.Hwang
 */
@Configuration
@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages = "com.keruyun.portal.whitelist.gateway")
//exclude = GatewayLoadBalancerClientAutoConfiguration.class
public class Bootstrap {
    public static void main(String[] args) {

        if (args.length < 2) {
            System.out.println("need input profile.active at position 2 in bootstrap commander ");
            return;
        }
        final String[] envParam = new String[]{"dev", "zbrd", "test", "citest", "gld", "gldexp", "vpcprodexp", "vpcprodexp", "lt", "local"};
        if (Arrays.stream(envParam).filter(Predicate.isEqual(args[1])).count() != 1) {
            System.out.println("with input profile.active param must in [\"dev\", \"zbrd\", \"test\", \"citest\", \"gld\", \"gldexp\", \"vpcprodexp\", \"vpcprodexp\", \"lt\",\"local\"]");
            return;
        }
        System.setProperty("profile.active", args[1]);
        System.out.println("-------------------------profile.active=" + args[1] + "-------------------------");
        SpringApplication.run(Bootstrap.class, args);

    }
//
//    @Bean
//    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
//        return builder.routes().
//                            //TEST
//                              route("biz", r -> r.path("/biz/**").filters(f -> f.stripPrefix(1)).uri("lb://WHITELIST-BIZ/**")).build();
//    }

}
